package Easy.q3;

import java.util.ArrayList;
import java.util.HashSet;

/*
 * 给定一个字符串，请你找出其中不含有重复字符的 最长子串 的长度。*/
public class q3 {
    public static void main(String[] args) {
        String s = "pwwkew";
        lengthOfLongestSubstring(s);
    }
    public static int lengthOfLongestSubstring(String s) {
        if (s == null || s == "") {
            return 0;
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < s.length() - 1; i++) {
            HashSet<Character> set = new HashSet<>();
            boolean flag = true;
            for (int j = i; j < s.length(); j++) {
                if (!set.add(s.charAt(j)))
                    break;
                if(j == s.length() - 2){
                    flag = false;
                }
            }
            list.add(set.size());
            if(!flag) break;
        }
        System.out.println(list);
        int max = 0;
        for (Integer integer : list) {
            max = integer > max ? integer : max;
        }
        return max;
    }
}
